1 <?php
2 session_start();
// Use session variable on this page. This function must put on the top of page.
3 if
(!isset($_SESSION['username']) || $_SESSION['usertype'] !='admin'){ // if session variable "username" does not exist.
4 header(
"location:index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php
5 }

6 else

7 {
8     include_once
"db.php";
9     error_reporting (E_ALL ^ E_NOTICE);
10     
if(isset($_GET['id']) && isset($_GET['table']))
11     {
12     $id=$_GET[
'id'];
13     $tablename=$_GET[
'table'];
14     $
return=$_GET['return'];
15     
16     
if($tablename=="stock_entries")
17     {
18                 $difference=$db->queryUniqueValue(
"SELECT quantity FROM stock_entries WHERE id=$id");
19                 
20                 $name=$db->queryUniqueValue(
"SELECT stock_name FROM stock_entries WHERE id=$id");
21                 $result=$db->query(
"SELECT * FROM stock_entries where id > $id");
22                 
while ($line2 = $db->fetchNextObject($result)) {
23                 $osd=$line2->opening_stock - $difference;
24                 $csd=$line2->closing_stock - $difference;
25                 $cid=$line2->id;
26                 $db->execute(
"UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
27                     
28                 }
29                 $total = $db->queryUniqueValue(
"SELECT quantity FROM stock_avail WHERE name='$name'");
30                 $total = $total - $difference;
31                 $db->execute(
"UPDATE stock_avail SET quantity=$total WHERE name='$name'");
32     }
33     
if($tablename=="stock_sales")
34     { $difference=$db->queryUniqueValue(
"SELECT quantity FROM stock_sales WHERE id=$id");
35                 $sid=$db->queryUniqueValue(
"SELECT transactionid FROM stock_sales WHERE id=$id");
36                 $id=$db->queryUniqueValue(
"SELECT id FROM stock_entries WHERE salesid='$sid'");
37                 $name=$db->queryUniqueValue(
"SELECT stock_name FROM stock_entries WHERE id=$id");
38                 $result=$db->query(
"SELECT * FROM stock_entries where id > $id");
39                 
while ($line2 = $db->fetchNextObject($result)) {
40                 $osd=$line2->opening_stock + $difference;
41                 $csd=$line2->closing_stock + $difference;
42                 $cid=$line2->id;
43                 $db->execute(
"UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
44                     
45                 }
46                 echo
"sale $name";
47                 $total = $db->queryUniqueValue(
"SELECT quantity FROM stock_avail WHERE name='$name'");
48                 $total = $total + $difference;
49                 $db->execute(
"UPDATE stock_avail SET quantity=$total WHERE name='$name'");
50                 $db->execute(
"DELETE FROM $tablename WHERE id=$id");
51     }
52     $id=$_GET[
'id'];
53     
54     $db->execute(
"DELETE FROM $tablename WHERE id=$id");
55     
56     header(
"location:$return?msg=Record Deleted Successfully!&id=$id");
57     }
58         
59
60     
61 }
62 ?>


Gõ tìm kiếm nhanh...